<?php
namespace app\admin\model;
use think\Db;
use think\Model;

class FrPriceRule extends Model
{
	 public function __construct()
	{
		parent::__construct();
	}

	//推广人员列表
    public function getListInfo($page,$limit,$data){
	     $where = [];
        //省份
        if(!empty($data['province_id'])){
            $where['province_id'] = $data['province_id'];
        }
        if(isset($data['provinceId']) && $data['provinceId'] != ''){
            $where['province_id'] = $data['provinceId'];
        }
        //城市ID
        if(!empty($data['city_id'])){
            $where['city_id'] = $data['city_id'];
        }
        if(isset($data['cityId']) && $data['cityId'] != ''){
            $where['city_id'] = $data['cityId'];
        }
        $where['status'] = 1;
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::table('fr_price_rule')->where($where)->count();
        $list = Db::table('fr_price_rule')->where($where)->limit($start, $limit)->order('rid','desc')->select();
        $inside_price = [];
        $provinceName = '';
        foreach ($list as $key=>$value){
            if(!empty($value['province_id'])){
                $list[$key]['provinceName'] = Db::name('region')->where('region_id', $value['province_id'])->value('region_name');
            }else{
                $list[$key]['provinceName'] = '默认省份';
            }
            $list[$key]['minute_money']     = $value['minute_money']/100;
            $list[$key]['user_punish']      = $value['user_punish']/100;
            $list[$key]['cancle_money']     = ($value['order_punish']/10).'% / '.($value['user_cancel']/10).'%';
            $list[$key]['plate_fee']        = ($value['plate_fee']/10).'%';
            if(!empty($value['inside_price'])){
                $inside_price = json_decode($value['inside_price'],true);
                $list[$key]['insidePriceType']  = 1;
                $list[$key]['mileage']  = $inside_price[0]['startMileage'].' - '.$inside_price[0]['endMileage'];
                $list[$key]['money']    = $inside_price[0]['poolCarMoney'].' / '.$inside_price[0]['poolCarMoneyNo'];
            }else{
                $list[$key]['insidePriceType']  = 0;
                $list[$key]['mileage']  = ' - ';
                $list[$key]['money']    = ' - ';
            }

            if(empty($value['suburb_price'])){
                $list[$key]['suburbPriceType']  = 0;
            }else{
                $list[$key]['suburbPriceType']  = 1;
            }

        }
        return array(
            'code'  => 0,
            'msg'   => '',
            'count' => $count,
            'data'  => $list
        );
    }
}
